/**
 * Copyright (c) 2020 xstgongyi.org
 * All rights reserved.
 */
package org.xstgongyi.eduaid.manager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.xstgongyi.eduaid.dao.StudentMapper;
import org.xstgongyi.eduaid.dataobject.StudentDO;

import java.util.List;
import java.util.Map;

/**
 * @author oldcrane<br/>
 * @created 2020-10-12
 */
@Service
@CacheConfig(cacheNames = "student")
public class StudentManager {

    @Autowired
    private StudentMapper dao;

    @Cacheable(key = "#id")
    public StudentDO getById(Integer id){
        return dao.getById(id);
    }

    public List<StudentDO> listAll(){
        return dao.listAll();
    }

    public List<StudentDO> listByProject(Integer projectId){
        return dao.listByProject(projectId);
    }

    public List<StudentDO> listPage(Map<String, Object> condition){
        return dao.listPage(condition);
    }

    public int countTotal(Map<String, Object> condition){
        return dao.countTotal(condition);
    }

    public int insert(StudentDO student) {
        return dao.insert(student);
    }

    @CacheEvict(key="#student.id")
    public int update(StudentDO student){
        return dao.update(student);
    }

    // 根据学生编号前缀，查找最大的学生编号
    public String getMaxSn(String snPattern){
        return dao.getMaxSn(snPattern);
    }

}
